package config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.OkHttp3ClientHttpRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

/**
 * RestTemplate相关类在spring-web依赖里
 */
@Configuration
public class RestTemplateConfig {
    @Bean
    public ClientHttpRequestFactory clientHttpRequestFactory(){
      /*  SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
        return factory;*/
        //如果使用OkHttp3ClientHttpRequestFactory就需要添加okhttp库的依赖
        OkHttp3ClientHttpRequestFactory factory = new OkHttp3ClientHttpRequestFactory();
        return factory;
    }

    @Bean
    public RestTemplate restTemplate(){
        RestTemplate template = new RestTemplate(clientHttpRequestFactory());
        return template;
    }
}
